#!/usr/bin/env python3
"""
HTTP Server 启动入口
"""

import os
import sys
from pathlib import Path

# Add the project root to the Python path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from src.http_server import start_server

if __name__ == "__main__":
    # Load environment variables
    from dotenv import load_dotenv
    load_dotenv()
    
    # Check for API key
    if not os.getenv("ZHIPU_API_KEY"):
        print("❌ 错误: ZHIPU_API_KEY环境变量必须设置")
        print("请运行: export ZHIPU_API_KEY='your_api_key'")
        sys.exit(1)
    
    import argparse
    
    parser = argparse.ArgumentParser(description="CogView MCP HTTP Server")
    parser.add_argument("--host", default="localhost", help="Host to bind to (default: localhost)")
    parser.add_argument("--port", type=int, default=8000, help="Port to bind to (default: 8000)")
    
    args = parser.parse_args()
    
    print(f"🚀 启动CogView MCP HTTP服务器")
    print(f"📍 服务器地址: http://{args.host}:{args.port}")
    print(f"📖 API文档: http://{args.host}:{args.port}/docs")
    print(f"💡 在Cline中配置URL: http://{args.host}:{args.port}")
    print("=" * 50)
    
    start_server(args.host, args.port)
